import {
  userInfo
} from "../../api/user.js"
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info: '',
    navlist: [{
        title: '我的收藏',
        icon: "/img/l1_icon.png",
        width: 28,
        height: 29,
        path: '/packageA/collect/index'
      },
      {
        title: '我的活动',
        icon: "/img/l2_icon.png",
        width: 25,
        height: 31,
        path: '/packageA/myactivity/index'
      },
      {
        title: '我的订单',
        icon: "/img/order.png",
        width: 25,
        height: 31,
        path: '/packageA/order/order'
      },
      {
        title: '设置',
        icon: "/img/l3_icon.png",
        width: 29,
        height: 28,
        path: '/packageA/set/index'
      },
      {
        title: '关于我们',
        icon: "/img/l4_icon.png",
        width: 28,
        height: 28,
        path: '/packageA/about/index'
      },
      {
        title: '联系客服',
        icon: "/img/l5_icon.png",
        width: 28,
        height: 28,
        path: '',
        id: 4
      },
    ],
    isLog: getApp().globalData.token
  },
  getUserInfo() {
    if (app.globalData.token != '') {
      userInfo().then(res => {
        var info = {
          avatarUrl:'/img/l7_tx.png',
          nickName:'微信用户'
        }
        if (res.user.userProfile.picture == '') {
          info.avatarUrl = '/img/l7_tx.png'
        }else if(res.user.userProfile.picture.substring(0,4) == 'http'){
          info.avatarUrl = res.user.userProfile.picture
        }else{
          info.avatarUrl = app.globalData.$https + res.user.userProfile.picture
        }
        info.nickName = res.user.userProfile.nickname || res.user.phone || '微信用户'
        this.setData({
          info: info
        })
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  welcome() {
    wx.navigateTo({
      url: '../welcome/welcome',
    })
  },
  zaixiankefu(){
    wx.navigateTo({
      url: '../customer/customer',
    })
  },
  jumpsp(e) {
    var {
      index
    } = e.currentTarget.dataset
    var jumpobj = this.data.navlist[index]
    if (this.data.isLog) {
      if (jumpobj.id == 4) {
        wx.makePhoneCall({
          phoneNumber: '400-061-5566'
        })
      } else {
        wx.navigateTo({
          url: jumpobj.path,
        })
      }
    } else {
      wx.navigateTo({
        url: '/pages/welcome/welcome',
      })
    }
  },
  goprofile() {
    wx.navigateTo({
      url: '/packageA/profile/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      isLog: getApp().globalData.token
    })
    if (getApp().globalData.token) {
      this.getUserInfo()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})